package 删除链表的倒数第N个节点;


public class Test {
    public static void main(String[] args) {

        ListNode l4 = new ListNode(5, null);
        ListNode l3 = new ListNode(4, l4);
        ListNode l2 = new ListNode(3, l3);
        ListNode l1 = new ListNode(2, l2);
        ListNode head = new ListNode(1, l1);

        /*ListNode l1 = new ListNode(5, null);
        ListNode head = new ListNode(6, l1);*/

        ListNode head1 = new ListNode(6, null);

        /*ListNode l2 = new ListNode(4, null);
        ListNode l1 = new ListNode(5, l2);
        ListNode head = new ListNode(6, l1);*/

        printM(head);
        Solution s1 = new Solution();
        ListNode result = s1.removeNthFromEnd(head, 5);

        printM(result);

    }

    public static void printM(ListNode head) {
        ListNode p = new ListNode();
        p = head;
        while (p != null) {
            System.out.print(p.val + " ");
            p = p.next;
        }
        System.out.println();
    }
}

